package com.antd.common.auth.security;

import com.antd.admin.api.entity.SysUser;
import com.antd.common.core.constant.Constant;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * TODO
 *
 * @author 冷言丶冷语
 * @version 1.0
 * @date 2020/10/13 16:58
 */
@Data
public class AntdUserDetails implements UserDetails {
    private static final long serialVersionUID = 1L;
    private String userId;
    private String username;
    private Collection<? extends GrantedAuthority> authorities;
    private String password;
    private SysUser user;
    private String deptId;
    private Integer lockFlag=0;
    public AntdUserDetails(String userId, String username, String password, Collection<? extends GrantedAuthority> authorities,Integer lockFlag){
        this.userId=userId;
        this.username=username;
        this.password=password;
        this.authorities=authorities;
        this.lockFlag=lockFlag;
    }
    public AntdUserDetails(String userId, String username, String password, Collection<? extends GrantedAuthority> authorities){
        this.userId=userId;
        this.username=username;
        this.password=password;
        this.authorities=authorities;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
         return authorities;
    }
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return Constant.USER_STATUS_NORMAL.equals(this.lockFlag)?true:false;
    }
}
